package com.javaee.xiangyang.controller.Admin;


import com.javaee.xiangyang.dto.OrderGoods;
import com.javaee.xiangyang.entity.Order;
import com.javaee.xiangyang.entity.User;
import com.javaee.xiangyang.entity.enmu.impl.OrderState;
import com.javaee.xiangyang.entity.enmu.impl.UserState;
import com.javaee.xiangyang.service.AccountService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/Users")
@Controller
public class UsersController {

    @Resource
    AccountService accountService;

    @RequestMapping("/Management")
    public ModelAndView getAllUser(ModelAndView modelAndView) {
        List<User> allUser = accountService.getAllUser();
        modelAndView.addObject("allUser", allUser);
        modelAndView.setViewName("admin/user_list");
        return modelAndView;
    }

    //根据用户状态查找
    //包括模糊查询
    @RequestMapping("/Something")
    public ModelAndView getOrderManagementListByState(ModelAndView modelAndView, User user, String string) {
        //存在此状态
        //根据订单状态查找对应状态的订单
        List<User> orderByState = accountService.getAllUserByState(user, string);
        modelAndView.addObject("allUser", orderByState);
        if (user.getUserState() != null) {
            //传入订单状态
            modelAndView.addObject("state", user.getUserState().getCode());
        }
        modelAndView.setViewName("admin/user_list");
        return modelAndView;

    }

    //用户增加金额
    @RequestMapping("/AddMoney")
    public ModelAndView updateUserMoney(ModelAndView modelAndView, User user) {
        accountService.userUpdateMoney(user);
        modelAndView.setViewName("redirect:/Users/Management");
        return modelAndView;
    }

    //用户更改状态
    @RequestMapping("/UpdateState")
    public ModelAndView updateUserState(ModelAndView modelAndView, User user) {
        accountService.userUpdateState(user);
        modelAndView.setViewName("redirect:/Users/Management");
        return modelAndView;
    }

}
